package com.wangfugui.mybatisplus.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("分页响应基类")
public class PageResult<T> {

    @ApiModelProperty("当前页码")
    private Long pageNum;

    @ApiModelProperty("每页数量")
    private Long pageSize;

    @ApiModelProperty("总记录数")
    private Long total;

    @ApiModelProperty("总页数")
    private Long pages;

    @ApiModelProperty("分页数据列表")
    private List<T> list;

    public PageResult(IPage<T> page) {
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.total = page.getTotal();
        this.pages = page.getPages();
        this.list = page.getRecords();
    }

    public static <T> PageResult<T> success(IPage<T> page) {
        return new PageResult<>(page);
    }
}